package com.example.tests;

import java.util.concurrent.TimeUnit;
import org.openqa.selenium.Dimension;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.firefox.FirefoxDriver;
import org.testng.annotations.AfterClass;
import org.testng.annotations.BeforeClass;
import com.example.pages.AddMoviePage;
import com.example.pages.FilmPage;
import com.example.pages.HomePage;
import com.example.pages.InternalPage;
import com.example.pages.LoginPage;
import com.example.pages.MyPageFactory;
import com.example.pages.UserPage;

public class TestBase {

	protected WebDriver driver;
	protected String baseUrl;
	public LoginPage loginPage;
	public InternalPage internalPage;
	public UserPage userPage;
	public HomePage homePage;
	public FilmPage filmPage;
	public AddMoviePage addMoviePage;
	public static String email = "panterka.test@gmail.com";
	public static String login = "admin";
	public static String newPass = "123456";
	public static String incorrectConfirmPass = "1234";
	public static String oldPass = "admin";
	public static String filmTestTitle = "AboutTestsFilm";
	public static String newTestTitle = "AboutTrams";
	public static String newIMDB = "2";
	public String errorMes = "";

	@BeforeClass
	public void setUp() throws Exception {
		driver = new FirefoxDriver();
		driver.manage().timeouts().implicitlyWait(10, TimeUnit.SECONDS);
		Dimension dim = new Dimension(1600, 900);
		driver.manage().window().setSize(dim);
		baseUrl = "http://127.0.0.1/";
	}

	@AfterClass
	public void tearDown() throws Exception {
		driver.quit();
	}

	public LoginPage goToMainPage() {
		driver.get(baseUrl + "php4dvd/");
		return MyPageFactory.getPage(driver, LoginPage.class);
	}

	protected void fail(String message) {
		System.out.println("Error:" + message);
		throw new RuntimeException(message);
	}

	public boolean verify(WebElement el) {
		try {
			el.isDisplayed();
			return true;
		} catch (Exception e) {
			return false;
		}
	}
}